﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using MDA;



public partial class Users_AddUser : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //清空缓存方法
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.Cache.SetAllowResponseInBrowserHistory(false);
        tbUserName.Focus();
        if (!IsPostBack)
        {
            GetDataIni();
        }
    }

    /// <summary>
    /// 页面控件数据初始化

    /// </summary>
    private void GetDataIni()
    {
        //PageStyle.BindDdlNoEmpty(ddlDepartName, "lib_sort", "libaddress", "libaddress");
        //PageStyle.BindDdlNoEmpty(ddlRoleName, "T_depart_Role", "rolename", "rolename","departname='"+ddlDepartName.SelectedValue+"'");
    }


    /// <summary>
    /// 确定新增
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Button2_Click(object sender, EventArgs e)
    {
        try
        {
            T_USERData data = new T_USERData();
            //data.DEPARTNAME = ddlDepartName.SelectedValue;
            string pw=FormsAuthentication.HashPasswordForStoringInConfigFile("jiedai520..","MD5");
            data.USERID = "0";
            data.PASSWORD =  pw;
            data.REGDATE = DateTime.Now;
            data.REMARK = tbRemark.Text;
            data.USERNAME = tbUserName.Text;
            data.TRUENAME = tbTrueName.Text;
            data.STATE = 1;
            //data.ROLENAME = ddlRoleName.SelectedValue;
            //data.HasPopedom = 1;
            T_USERAccess ac = new T_USERAccess();
            ac.Insert(data);

            PageStyle.Show(this.Page, "用户添加成功");
            PageStyle.RegisterStartScript(this.Page, "returnValue='1';", "reval");
        }
        catch(System.Data.SqlClient.SqlException ex1)
        {
            if (ex1.Message.Contains("PRIMARY KEY"))
            {
                tbUserName.Focus();
                PageStyle.Show(this.Page, "该用户已经存在，请检查数据！");
            }
            else PageStyle.Show(this.Page, "数据保存失败，请检查数据！");
        }
        catch (System.Exception ex)
        {
            PageStyle.Show(this.Page,"数据保存失败，请检查数据！");
        }
    }
    /// <summary>
    /// 当单位发生改变时，角色也发生相应的变化。

    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ddlDepartName_SelectedIndexChanged(object sender, EventArgs e)
    {
        //PageStyle.BindDdlNoEmpty(ddlRoleName, "T_depart_Role", "rolename", "rolename", "departname='" + ddlDepartName.SelectedValue + "'");
    }
}
